package logic

import (
	"context"
	"exam/exzmrpc/exzmrpcclient"

	"exam/api/internal/svc"
	"exam/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
	return &CreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateLogic) Create(req *types.CreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	create, err := l.svcCtx.ExamRpc.Create(l.ctx, &exzmrpcclient.CreateRequest{
		Title:  req.Title,
		Number: req.Number,
		Types:  req.Types,
	})
	if err != nil {
		return &types.Response{
			Message: "添加课程失败",
			Code:    400,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "课程添加成功",
		Code:    200,
		Data:    create,
	}, nil
}
